package com.ruoyi.platform.system.menu.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

import static com.ruoyi.platform.system.menu.enums.MenuTypeEnum.*;


/**
 * 菜单
 *
 * @author lcf
 */
public enum MenuEnum {
    /**
     * 系统管理
     */
    SYS_MANAGE("1", "0", LIST, "系统管理"),
    /**
     * 用户管理
     */
    USER_MANAGEMENT("1_1", "1", MENU, "用户管理"),
    USER_MANAGEMENT_ADD("1_1_1", "1_1", BUTTON, "新增用户"),
    USER_MANAGEMENT_DEL("1_1_2", "1_1", BUTTON, "删除用户"),
    USER_MANAGEMENT_EDIT("1_1_3", "1_1", BUTTON, "修改用户"),
    USER_MANAGEMENT_SELECT("1_1_4", "1_1", BUTTON, "查看用户"),

    /**
     * 部门管理
     */
    DEPT_MANAGE("1_2", "1", MENU, "部门管理"),
    DEPT_MANAGE_ADD("1_2_1", "1_2", BUTTON, "新增部门"),
    DEPT_MANAGE_DEL("1_2_2", "1_2", BUTTON, "删除部门"),
    DEPT_MANAGE_EDIT("1_2_3", "1_2", BUTTON, "修改部门"),
    DEPT_MANAGE_SELECT("1_2_4", "1_2", BUTTON, "查看部门");

    /**
     * 菜单id
     */
    @Getter
    private String code;
    /**
     * 父菜单id
     */
    @Getter
    private String parentCode;
    /**
     * 菜单名称
     */
    @Getter
    private String menuName;
    /**
     * 菜单类型1目录2菜单3按钮
     */
    @Getter
    private int menuType;
    /**
     * 路由
     */
    @Getter
    private String path;

    MenuEnum(String code, String parentCode, MenuTypeEnum menuType, String menuName) {
        this.code = code;
        this.parentCode = parentCode;
        this.menuType = menuType.getMenuType();
        this.menuName = menuName;
    }

    MenuEnum(String code, String parentCode, MenuTypeEnum menuType, String menuName, String path) {
        this.code = code;
        this.parentCode = parentCode;
        this.menuType = menuType.getMenuType();
        this.menuName = menuName;
        this.path = path;
    }

    public static MenuEnum ofCode(String code) {
        return Arrays.stream(MenuEnum.values())
                .filter(x -> Objects.equals(x.getCode(), code))
                .findAny().orElse(null);
    }
}
